import { getOptions } from '@/api/common'
const optionsKey = 'comboboxKey'
export function getOptionsByCodeType(codeType) {
  return new Promise((resolve, reject) => {
    const optionsLs = JSON.parse(localStorage.getItem(optionsKey)) || {}
    if (!optionsLs[codeType]) {
      getOptions(codeType).then(response => {
        optionsLs[codeType] = response
        localStorage.setItem(optionsKey, JSON.stringify(optionsLs))
        resolve(response)
      })
    } else {
      resolve(optionsLs[codeType])
    }
  }
  )
}

export function clearOptions() {
  localStorage.removeItem(optionsKey)
}
